package com.hbt.orderfood.activity;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hbt.orderfood.R;
import com.hbt.orderfood.adapter.MySubmitOrderAdapter;
import com.hbt.orderfood.db.DBAdapter;
import com.hbt.orderfood.entitys.Order;
import com.hbt.orderfood.utils.StringUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MySubmitOrderActivity extends AppCompatActivity {

    @BindView(R.id.recycle)
    RecyclerView recycle;
    @BindView(R.id.total_price)
    TextView totalPrice;
    private MySubmitOrderAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_submit_order);
        ButterKnife.bind(this);
        setTitle("已经提交的订单");
        initRecycler();

//        totalPrice.setText(String.valueOf(adapter.getTotal_price()));
    }

    int getTotalPrice(List<Order> orders){
        int price = 0;
        for (Order o:orders){
            price+=o.getPrice();
        }
        return price;
    }
    void initRecycler() {
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recycle.setLayoutManager(layoutManager);
        List<Order> orders = new DBAdapter(this).getOrdersByUserID(String.valueOf(StringUtils.USERID));
        adapter = new MySubmitOrderAdapter(orders);
        totalPrice.setText("总计："+getTotalPrice(orders)+"￥");
        adapter.setTotal_price_text_view(totalPrice);
        recycle.setAdapter(adapter);
    }

}
